<template>
  <page-header-wrapper>
    <a-card :bordered="false">
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="24">
            <a-col
              :md="6"
              :sm="16">
              <a-form-item label="执行人">
                <a-select
                  show-search
                  :filter-option="filterOption"
                  v-model="queryParam.userId"
                  placeholder="请选择执行人">
                  <a-select-option
                    v-for="i in staffs"
                    :key="i.userId">
                    {{ i.name }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col
              :md="6"
              :sm="16">
              <a-form-item label="任务等级">
                <a-select
                  v-model="queryParam.level"
                  placeholder="请选择">
                  <a-select-option :value="1">紧急</a-select-option>
                  <a-select-option :value="2">加急</a-select-option>
                  <a-select-option :value="3">普通</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col
              :md="6"
              :sm="16">
              <!-- <a-form-item label="状态">
                <a-input
                  v-model="queryParam.jobs"
                  placeholder="" />
              </a-form-item> -->
            </a-col>
            <a-col
              :md="6"
              :sm="16">
              <span
                class="table-page-search-submitButtons">
                <a-button
                  type="primary"
                  @click="$refs.table.refresh(true)">查询</a-button>
                <a-button
                  style="margin-left: 8px"
                  @click="() => {this.queryParam = {};; this.$refs.table.refresh()}">重置</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <div>
        <a-row
          :gutter="
            48">
          <a-col
            :md="24"
            :sm="24">
            <s-table
              ref="table"
              size="default"
              rowKey="taskId"
              :columns="columns"
              :data="loadData"
              showPagination="auto"
              :customRow="tableCustomRow">
              <span
                slot="serial"
                slot-scope="text, record, index">
                {{ index + 1 }}
              </span>
              <span
                slot="beginDate"
                slot-scope="text, record">
                {{ record.beginDate.split(' ')[0] }}
              </span>
              <span
                slot="completeDate"
                slot-scope="text, record">
                {{ record.completeDate? record.completeDate.split(' ')[0]: '' }}
              </span>
              <span
                slot="planCompleteDate"
                slot-scope="text, record">
                {{ record.planCompleteDate? record.planCompleteDate.split(' ')[0]: '' }}
              </span>
              <span
                slot="action"
                slot-scope="text, record">
                <template>
                  <a @click="handleEdit(record)">配置</a>
                </template>
              </span>
            </s-table>
          </a-col>
        </a-row>
        <!-- <create-form
        ref="createModal"
        :visible="visible"
        :loading="confirmLoading"
        :model="mdl"
        @cancel="handleCancel"
        @ok="handleOk" /> -->
      </div></a-card>
  </page-header-wrapper>
</template>

<script>
import { STable } from '@/components'
import { getTaskList, allStaff } from '@/api/manage'
import { columns } from './config'
import CreateForm from './modules/CreateForm'
import { isInMenu } from '../config.js'
import { mapGetters } from 'vuex'

export default {
  name: 'TableList',
  components: {
    STable,
    CreateForm
  },
  data () {
    this.columns = columns
    return {
                       // 权限参数
      list: false, // 列表
      // create model
      visible: false,
      confirmLoading: false,
      // 查询参数
      queryParam: {},
      staffs: [],
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        const requestParameters = { page: parameter.pageNo, limit: parameter.pageSize }
        return getTaskList(Object.assign({}, this.queryParam, requestParameters)).then(res => {
          return Object.assign({}, res, {
            totalCount: res.total,
            pageNo: parameter.pageNo,
            pageSize: parameter.pageSize
          })
        })
      },
      staffInfo: {},
      selectedRowKeys: [],
      selectedRows: [],
      physicalSurveyCurrRowId: null
    }
  },
  filters: {},
  created () {
    this.list = isInMenu(this.menu, 'ROLE_but:task:list') && isInMenu(this.menu, 'ROLE_but:user:select')
  },
  mounted () {
    this.list && allStaff({}).then(res => {
      this.staffs = res.data
    })
  },
  computed: {
    ...mapGetters(['menu'])
  },
  methods: {
    handleChange ({ fileList }) {
      this.fileList = fileList
    },
    handleAdd () {
      this.updateRecordData = null
      this.visible = true
    },
    handleEdit (record) {
      this.visible = true
      this.showModal = true
    },
    handleOk () {
    },
    handleCancel () {
      this.visible = false

      const form = this.$refs.createModal.form
      form.resetFields() // 清理表单数据（可不做）
    },
    filterOption (input, option) {
      return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
    },
    tableCustomRow (record, index) {
      return {
        style: {
          'background-color': record.taskId === this.physicalSurveyCurrRowId ? '#dff3fe' : 'white'
        },
        on: {
          click: event => {
            this.physicalSurveyCurrRowId = record.taskId
            this.staffInfo = record
          }
        }
      }
    }
  }
}
</script>
